package com.changzhi.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.changzhi.common.constans.RedisConstans;
import com.changzhi.ldyl.model.*;
import com.changzhi.mapper.*;
import com.changzhi.service.TanabataService;
import com.changzhi.service.UserDressUpService;
import com.changzhi.util.CommonUtil;
import com.changzhi.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Description:测试
 * @author: 小落
 * @date: 2020年10月10日
 */
@RestController
@RequestMapping("initActivity")
@Slf4j
public class InitActivityController {

	@Autowired
	private RedisUtil redisUtil;
	@Resource
	private ActivityRecordMapper activityRecordMapper;
	@Resource
	private ActivityWalletMapper activityWalletMapper;
	@Autowired
	private ActivityDayMapper activityDayMapper;
	@Autowired
	private UserDressUpService userDressUpService;
	@Autowired
	private ActivityDataMapper activityDataMapper;
	@Resource
	private TanabataService tanabataService;
	@Resource
	private UserGiftMapper userGiftMapper;

	@GetMapping("tt")
	public Object tt(String pwd) {
		CommonUtil.checkPwd(pwd);
		LambdaQueryWrapper<UserGift> wrapper = new LambdaQueryWrapper<>();
		wrapper.in(UserGift::getId, 20354413,
				20354489,
				20354560,
				20354561,
				20354667,
				20354733,
				20354872,
				20354881,
				20354999,
				20355006,
				20355074,
				20355078
				);
		List<UserGift> userGifts = userGiftMapper.selectList(wrapper);
		for (UserGift userGift : userGifts) {
			tanabataService.doMqDataByUserGift(userGift);
		}
		return "ok";
	}

	@GetMapping("clearMatch")
	public Object clearMatch(String pwd) {
		CommonUtil.checkPwd(pwd);
		Integer activityId = 28;
		//清除活动记录
		activityRecordMapper.delete(new LambdaQueryWrapper<ActivityRecord>().eq(ActivityRecord::getActivityId, activityId));
		//清除装饰
		userDressUpService.remove(new LambdaQueryWrapper<UserDressUp>().eq(UserDressUp::getRemark, "王者争霸赛获得"));
		//删除缓存
		//redisUtil.del(RedisConstans.SIGN_SHOW);
		Set<String> strings0 = redisUtil.scanKey("user:dress_up_list:" + "*", 2000);
		for (String s : strings0) {
			redisUtil.del(s);
		}
		return "ok";
	}

	@PostMapping("init")
	public Object givePrize(@RequestBody Map<String,Object> map) {
		CommonUtil.checkPwd((String) map.get("pwd"));
		Integer activityId = 29;
		//清除活动记录
		activityRecordMapper.delete(new LambdaQueryWrapper<ActivityRecord>().eq(ActivityRecord::getActivityId, activityId));
		//清除活动钱包
		activityWalletMapper.delete(new LambdaQueryWrapper<ActivityWallet>().eq(ActivityWallet::getActivityId, activityId));
		//清除活动数据
		activityDataMapper.delete(new LambdaQueryWrapper<ActivityData>().eq(ActivityData::getActivityId, activityId));
		//清楚活动天数据
		activityDayMapper.delete(new LambdaQueryWrapper<ActivityDay>().eq(ActivityDay::getActivityId, activityId));
		//清除装饰
		userDressUpService.remove(new LambdaQueryWrapper<UserDressUp>().eq(UserDressUp::getRemark, "七夕活动获得"));
		//删除缓存
		//redisUtil.del(RedisConstans.SIGN_SHOW);
		Set<String> strings0 = redisUtil.scanKey(RedisConstans.ACTIVITY_RANKING + activityId + "*", 2000);
		for (String s : strings0) {
			redisUtil.del(s);
		}
		Set<String> strings1 = redisUtil.scanKey(RedisConstans.putRediskey(RedisConstans.ACTIVITY_FLAG, activityId) + "*", 2000);
		for (String s : strings1) {
			redisUtil.del(s);
		}
		Set<String> strings2 = redisUtil.scanKey(RedisConstans.putRediskey(RedisConstans.PRIZE_RECORD, activityId) + "*", 2000);
		for (String s : strings2) {
			redisUtil.del(s);
		}
		Set<String> strings = redisUtil.scanKey(RedisConstans.putRediskey(RedisConstans.WALLET, activityId) + "*", 2000);
		for (String string : strings) {
			redisUtil.del(string);
		}
		return "ok";
	}

}
